package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v1/channel") ///api/v1/channel/list
@Api(tags = "频道管理")
public class WmChannelController {

    @Autowired
    private IWmChannelService channelService;

    @PostMapping(value = "/list",name = "根据名称分页查询")
    @ApiOperation(value = "listByName" ,notes = "根据名称分页查询")
    @ApiModelProperty(name ="dto" ,dataType = "ChannelDto" ,required = true)
    public ResponseResult listByName(@RequestBody ChannelDto dto){
        return channelService.listByName(dto);
    }

    @PostMapping(name = "判断新增")
    @ApiOperation(value = "saveWmChannel" ,notes = "根据名称分页查询")
    @ApiModelProperty(name ="wmChannel" ,dataType = "WmChannel" ,required = true)
    public ResponseResult saveWmChannel(@RequestBody WmChannel wmChannel){
        return channelService.saveWmChannel(wmChannel);
    }

    @GetMapping(value = "/channels",name = "查询所有频道")
    public ResponseResult channels(){
        List<WmChannel> wmChannelList = channelService.list();
        return ResponseResult.okResult(wmChannelList);
    }
}
